package com.shrct.businessprocess.project.impl;

import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.project.RCCustomerContract;
import com.shrct.businessprocess.project.RCCustomerContractCriteria;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;

public class RCCustomerContractCriteriaImpl extends HQLBasedPagedQueryCriteria<RCCustomerContract> implements RCCustomerContractCriteria {
  private String contractId;
  
  public String getContractId() {
    return this.contractId;
  }
  
  public RCCustomerContractCriteria setContractId(final String contractId) {
    this.contractId = contractId;
    return this;			
    
  }
  
  private String projectInfo;
  
  public String getProjectInfo() {
    return this.projectInfo;
  }
  
  public RCCustomerContractCriteria setProjectInfo(final String projectInfo) {
    this.projectInfo = projectInfo;
    return this;			
    
  }
  
  private RCEnterprise customer;
  
  public RCEnterprise getCustomer() {
    return this.customer;
  }
  
  public RCCustomerContractCriteria setCustomer(final RCEnterprise customer) {
    this.customer = customer;
    return this;			
    
  }
  
  private Boolean notFinishedOnly;
  
  public Boolean getNotFinishedOnly() {
    return this.notFinishedOnly;
  }
  
  public RCCustomerContractCriteria setNotFinishedOnly(final Boolean notFinishedOnly) {
    this.notFinishedOnly = notFinishedOnly;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.project.impl.RCCustomerContractImpl this  left join  this.moneyAccepts as accept ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getNotFinishedOnly()) ){
    	hql += " and (((accept.assignFinished) = (false)) or ((:notFinishedOnly) = (false)))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getContractId()) ){
    	hql += " and (this.contractId  LIKE :contractId)" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectInfo()) ){
    	hql += " and ((this.project.name  LIKE :projectInfo) or (this.project.code  LIKE :projectInfo))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCustomer()) ){
    	hql += " and (this.customer  LIKE :customer)" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getContractId())){
    	query.setParameter("contractId",getContractId()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectInfo())){
    	query.setParameter("projectInfo",getProjectInfo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCustomer())){
    	query.setParameter("customer",getCustomer()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getNotFinishedOnly())){
    	query.setParameter("notFinishedOnly",getNotFinishedOnly()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return true;
  }
  
  public RCCustomerContractCriteriaImpl() {
    initOrderBys();
  }
}
